<template>
  <div id="dg">
    <b-notification
        type="is-info is-light"
        aria-close-label="Close notification"
        v-if="now.pointId != 1"
        @click="goOn(father.pointId, 2)"
    >
      父节点：{{ father.pointName }}
    </b-notification>
    <b-notification
        type="is-success is-light"
        aria-close-label="Close notification"
    >
      当前节点: {{ now.pointName }}
    </b-notification>

    <vs-table class="ta" v-if="son.length!=0">
      <template #thead>

        <vs-tr class="tr">
          <vs-th> 子节点名</vs-th>
        </vs-tr>
      </template>

      <template #tbody>
        <vs-tr
            :key="i"
            v-for="(tr, i) in son"
            :data="tr"
            @click="goOn(tr.point2.pointId, 1)"
        >

          <vs-td>
            {{ tr.point2.pointName }}
          </vs-td>

        </vs-tr>
      </template>

    </vs-table>

    <b-button type="is-light" v-if="son.length==0" @click="go(now.pointId)">进入知识点</b-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      father: "",
      now: "",
      son: "",
      columns: [
        {
          field: "point2.pointName",
          label: "子节点名",
        },
      ],
    };
  },
  methods: {
    go(value) {
      this.$router.push({path: "/videoAndPdf", query: {value: value}})
    },
    async findF(poinId) {
      let res = await this.$http.get("api/2backcode/edge/findf", {
        params: {
          pointId: poinId
        }
      })
      console.log(res.data)
      this.father = res.data[0].point1
    },
    async goOn(pointId, a) {
      if (a == 1) {
        this.father = this.now;
      } else if (a == 2) {
        this.findF(pointId)
      }
      this.now = await this.$http.get("api/2backcode/point/findone", {
        params: {
          pointId: pointId,
        },
      });
      this.now = this.now.data;
      this.son = await this.$http.get("api/2backcode/edge/find", {
        params: {
          pointId: pointId,
        },
      });

      this.son = this.son.data;
      for (let i = 0; i < this.son.length; i++) {
        if (this.son[i].afterId == -1) {
          this.son.splice(i, 1);
          i--;
        }
      }
    },
    async init() {
      var nowPointId = "1";
      this.now = await this.$http.get("api/2backcode/point/findone", {
        params: {
          pointId: nowPointId,
        },
      });
      this.now = this.now.data;
      this.son = await this.$http.get("api/2backcode/edge/find", {
        params: {
          pointId: nowPointId,
        },
      });
      this.son = this.son.data;
      for (let i = 0; i < this.son.length; i++) {
        if (this.son[i].afterId == -1) {
          this.son.splice(i, 1);
          i--;
        }
      }
    },
  },
  mounted() {
    this.init();
  },
};
</script>

<style>
#dg {
  width: 290px;
}
</style>
